package com.club.uni.controller;

import com.club.uni.config.PInit;
import com.club.uni.dto.PushUniDoing;
import com.club.uni.dto.PushVo;
import com.club.uni.config.CInit;
import com.club.uni.service.PushService;
import com.club.uni.utils.Result;
import com.club.uni.utils.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: wxj
 * @Date: 2021-04-28 16:12
 */
@RestController
@RequestMapping("/uni")
@Slf4j
public class PushController {

    @Autowired
    private CInit cInit;
    @Autowired
    private PInit pInit;
    @Autowired
    private PushService doPush;


    @PostMapping("push")
    public Result pushUni(@RequestBody PushVo pushVo){
        PushUniDoing pushUniDoing = new PushUniDoing();
        pushUniDoing.setCid(pushVo.getCid());
        pushUniDoing.setClientType(2);
        pushUniDoing.setTitle(pushVo.getTitle());
        pushUniDoing.setContent(pushVo.getContent());
        pushUniDoing.setPath("msg");
        if (pushVo.getType()==0){
            pushUniDoing.setPackageName(pInit.pageName());
            pushUniDoing.setPushApi(pInit.getPushApi());
            pushUniDoing.setUserApi(pInit.getUserApi());
        }else {
            pushUniDoing.setPackageName(cInit.pageName());
            pushUniDoing.setPushApi(cInit.getPushApi());
            pushUniDoing.setUserApi(cInit.getUserApi());
        }
        Map<String, Object> push = doPush.push(pushUniDoing);
        log.info("推送结果：{}",push);
        return  new Result(ResultCode.SUCCESS,push);
    }
}
